#!/usr/bin/env python

"""
PGM by GraphViz
"""

import graphviz

s = 1.2
name = 'TS'

if name == 'HMM':
    style = 'dashed'
elif name == 'TS':
    style = 'solid'
else:
    raise 'No such name!'

g = graphviz.Digraph(comment=name, filename=name, engine='neato', format="png")
g.attr(rankdir='LR')

with g.subgraph(name='cluster_1', node_attr={'shape':'circle'}) as c:
    c.attr(style='invis')
    for k, node in enumerate(['X1','X2', 'XX', 'XT']):
        if node == 'XX':
            c.node(node, label='...', shape='plaintext', pos=f'{k*s}, {s}!', fontname="Symbol")
        else:
            c.node(node, label=node, pos=f'{k*s}, {s}!', fontname="Symbol")
    # c.attr(label='Observable Variables')

with g.subgraph(name='cluster_2', node_attr={'shape':'circle'}) as c:
    c.attr(style='invis')
    for k, node in enumerate(['Y1','Y2', 'YY', 'YT']):
        if node == 'YY':
            c.node(node, label='...', shape='plaintext', pos=f'{k*s}, 0!', style=style, fontname="Symbol")
        else:
            c.node(node, label=node, pos=f'{k*s}, 0!', style=style, fontname="Symbol")
    # c.attr(label='Hiden Variables')

g.edges([('Y1', 'Y2'),('Y2', 'YY'), ('YY', 'YT')])

g.edge('Y1', 'X1')
g.edge('Y2', 'X2')
g.edge('YT', 'XT')

g.view()
